package cn.edu.hziee;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class UserServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");//
        String userName = request.getParameter("userName");
        String password = request.getParameter("password");
        String re_password = request.getParameter("re_password");
        RequestDispatcher rd = null;
        if (password.equals(re_password)) {
            System.out.println(userName);
            System.out.println(password);
            System.out.println(re_password);
            // 通过request传递数据
            request.setAttribute("psw",password);
            rd = request.getRequestDispatcher("WEB-INF/ok.jsp");
        }else {
            request.setAttribute("psw",password);
            request.setAttribute("psw2",re_password);
            rd = request.getRequestDispatcher("WEB-INF/fail.jsp");
        }
        request.setAttribute("name",userName);
        rd.forward(request,response);
    }


    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        RequestDispatcher rd =
                request.getRequestDispatcher("WEB-INF/register.jsp");
        rd.forward(request,response);
        System.out.println("12");
    }
}
